package com.itheima.dao.store;

import com.itheima.domain.store.Catalog;
import com.itheima.domain.store.Course;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.Date;
import java.util.List;

/**
 * 题库管理  -> 目录管理(阶段管理)(数据层)
 */
public interface CatalogDao {
    @Select("SELECT * FROM st_catalog")
    @Results(id="catalogMap",value = {
            @Result(property = "id", column = "id",jdbcType = JdbcType.VARCHAR,javaType = String.class),
            @Result(property = "name", column = "name",jdbcType = JdbcType.VARCHAR,javaType = String.class),
            @Result(property = "remark", column = "remark",jdbcType = JdbcType.VARCHAR,javaType = String.class),
            @Result(property = "state", column = "state",jdbcType = JdbcType.VARCHAR,javaType = String.class),
            @Result(property = "createTime", column = "create_time",jdbcType = JdbcType.TIMESTAMP,javaType = Date.class),
            @Result(property = "courseId", column = "course_id",jdbcType = JdbcType.VARCHAR,javaType = String.class),
            @Result(
                    property = "course",
                    column = "course_id",
                    jdbcType = JdbcType.VARCHAR,
                    javaType = Course.class,
                    one = @One(select = "com.itheima.dao.store.CourseDao.findById")
            )

    })
    List<Catalog> findAll();


    @Select("select * from st_catalog where id = #{id}")
    @ResultMap("catalogMap")
    Catalog findById(String id);

    @Insert("insert into st_catalog(id,name,remark,state,create_time,course_id) values(#{id},#{name},#{remark},#{state},#{createTime},#{courseId}) ")
    int save(Catalog catalog);


    @Update("update st_catalog set name=#{name},remark=#{remark},state=#{state},course_id=#{courseId} where id=#{id}")
    int update(Catalog catalog);


    @Delete("delete from st_catalog where id=#{id}")
    int deleteById(String id);
}
